using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using btnet;

/// <summary>
/// Summary description for edit_web_config
/// </summary>
public partial class edit_web_config : System.Web.UI.Page
{
    protected Security security;
    
///////////////////////////////////////////////////////////////////////
void Page_Load(Object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        String footer_label = null;
        if (Application["custom_footer"] != null)
        {
            footer_label = (String)Application["custom_footer"];
        }
        custom_footer_label.Text = footer_label;
    }

    
	Util.do_not_cache(Response);
	
	security = new Security();
	security.check_security( HttpContext.Current, Security.MUST_BE_ADMIN);

	titl.InnerText = Util.get_setting("AppTitle","BugTracker.NET") + " - "
		+ "edit Web.config";

    string path = HttpContext.Current.Server.MapPath(null);
    path += "\\Web.config";

    if (!IsPostBack)
    {
        System.IO.StreamReader sr = System.IO.File.OpenText(path);
        myedit.Value = sr.ReadToEnd();
        sr.Close();
        sr.Dispose();
        msg.InnerHtml = "&nbsp;";
    }
    else
    {
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        System.IO.StringReader stringReader = new System.IO.StringReader(myedit.Value);
        try
        {
            doc.Load(stringReader);
            System.IO.StreamWriter sw = System.IO.File.CreateText(path);
            sw.Write(myedit.Value);
            sw.Close();
            sw.Dispose();
            msg.InnerHtml = "Web.config was saved.";
        }
        catch (Exception ex)
        {
            msg.InnerHtml = "ERROR:" + ex.Message;        
        }
    }

    
}
}